package com.spsoft.core.utils;


/**
 * @Classname CrcUtil
 * @Description TODOc
 * @Author zhubin-029
 * @Date 2023/6/27
 */
public class CrcUtil {

	private int crc16 = 0x8005;
	private int a = 0x0000;

	public String getCRC(String input){
		try {

			byte[] inputs = input.getBytes("GBK");
			for (int i = 0; i < inputs.length; i ++){
				div(inputs[i]);
			}
			byte r = 0;
			div(r);
			div(r);
			return Integer.toHexString(a).toUpperCase();
		}catch (Exception e){
			return "";
		}
	}
	private void div(byte input) {
		int temp;
		int data = input;
		for (int i = 0; i < 8; i ++) {
			temp = a & 0x8000;
			a = a << 1;
			a = a & 0x0000ffff;
			int numIn = data & 0x80;numIn = numIn >> 7;
			a = a ^ numIn;
			if (temp == 0x8000) {
				a = a ^ crc16;

			}
			data = data << 1;a = a & 0x0000ffff;

		}

	}
}
